/*
 * © Copyright 2011 Romain Marteau, Matthieu Totet
 * 
 *    This file is part of VineaToum.
 *
 *    VineaToum is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    VineaToum is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with VineaToum.  If not, see <http://www.gnu.org/licenses/>.
 *    
 */

package org.vineatoum.view.data;

import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.JTextField;
import java.awt.Insets;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;

import org.vineatoum.business.configuration.Appellation;
import org.vineatoum.business.configuration.AppellationType;
import org.vineatoum.model.abstraction.IVineaToumModel;

public class AppellationDataPanel extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6779005200522265769L;
	private JTextField textField;
	private JComboBox comboBox;

	
	/**
	 * Create the panel.
	 * @param model 
	 */
	public AppellationDataPanel(Appellation appellation, IVineaToumModel model) {
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[]{0, 0, 0, 0, 0, 0};
		gbl_panel.rowHeights = new int[]{0, 0, 0, 0, 0, 0};
		gbl_panel.columnWeights = new double[]{0.0, 1.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
		gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
		setLayout(gbl_panel);
		
		JLabel lblDate = new JLabel("Nom");
		GridBagConstraints gbc_lblDate = new GridBagConstraints();
		gbc_lblDate.insets = new Insets(0, 0, 5, 5);
		gbc_lblDate.anchor = GridBagConstraints.EAST;
		gbc_lblDate.gridx = 0;
		gbc_lblDate.gridy = 0;
		add(lblDate, gbc_lblDate);
		
		setTextField(new JTextField(appellation.getName()));
		GridBagConstraints gbc_textField = new GridBagConstraints();
		gbc_textField.insets = new Insets(0, 0, 5, 5);
		gbc_textField.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField.gridx = 1;
		gbc_textField.gridy = 0;
		add(getTextField(), gbc_textField);
		getTextField().setColumns(10);
		
		JLabel lblType = new JLabel("Type");
		GridBagConstraints gbc_lblType = new GridBagConstraints();
		gbc_lblType.anchor = GridBagConstraints.EAST;
		gbc_lblType.insets = new Insets(0, 0, 5, 5);
		gbc_lblType.gridx = 0;
		gbc_lblType.gridy = 1;
		add(lblType, gbc_lblType);
		
		setComboBox(new JComboBox());
		List<AppellationType> data = new ArrayList<AppellationType>();
		for (Iterator<AppellationType> iterator = AppellationType.appellationTypes.iterator(); iterator.hasNext();) {
			AppellationType type = (AppellationType) iterator.next();
			if(type.getName() != null && !type.getName().isEmpty()) {
				data.add(type);
			}
			
		}
		getComboBox().setModel(new DefaultComboBoxModel(data.toArray()));
		getComboBox().setSelectedItem(appellation.getType());
		GridBagConstraints gbc_comboBox = new GridBagConstraints();
		gbc_comboBox.insets = new Insets(0, 0, 5, 5);
		gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
		gbc_comboBox.gridx = 1;
		gbc_comboBox.gridy = 1;
		add(getComboBox(), gbc_comboBox);
		
//		JLabel label = new JLabel(AppellationType.appellationTypes.size() + "");
//		GridBagConstraints gbc_label = new GridBagConstraints();
//		gbc_label.insets = new Insets(0, 0, 5, 5);
//		gbc_label.fill = GridBagConstraints.HORIZONTAL;
//		gbc_label.gridx = 2;
//		gbc_label.gridy = 1;
//		add(label, gbc_label);
	}


	/**
	 * @param textField the textField to set
	 */
	public void setTextField(JTextField textField) {
		this.textField = textField;
	}


	/**
	 * @return the textField
	 */
	public JTextField getTextField() {
		return textField;
	}


	/**
	 * @param comboBox the comboBox to set
	 */
	public void setComboBox(JComboBox comboBox) {
		this.comboBox = comboBox;
	}


	/**
	 * @return the comboBox
	 */
	public JComboBox getComboBox() {
		return comboBox;
	}

}
